package com.ruoyi.source.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.source.domain.GoodsOrder;
import com.ruoyi.source.mapper.GoodsOrderMapper;
import com.ruoyi.source.service.IGoodsOrderService;
import com.ruoyi.utils.TimestampIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import static com.ruoyi.common.utils.DateUtils.YYYY_MM_DD_HH_MM_SS;

/**
 * 货物订单Service业务层处理
 * 
 * @author lml
 * @date 2025-01-07
 */
@Service
public class GoodsOrderServiceImpl implements IGoodsOrderService 
{
    @Autowired
    private GoodsOrderMapper goodsOrderMapper;

    /**
     * 查询货物订单
     * 
     * @param id 货物订单主键
     * @return 货物订单
     */
    @Override
    public GoodsOrder selectGoodsOrderById(Long id)
    {
        return goodsOrderMapper.selectGoodsOrderById(id);
    }

    /**
     * 查询货物订单列表
     * 
     * @param goodsOrder 货物订单
     * @return 货物订单
     */
    @Override
    public List<GoodsOrder> selectGoodsOrderList(GoodsOrder goodsOrder)
    {
        System.out.println(goodsOrderMapper.selectGoodsOrderList(goodsOrder));
        return goodsOrderMapper.selectGoodsOrderList(goodsOrder);
    }

    /**
     * 新增货物订单
     * 
     * @param goodsOrder 货物订单
     * @return 结果
     */
    @Override
    public int insertGoodsOrder(GoodsOrder goodsOrder) throws InterruptedException {
        goodsOrder.setId(TimestampIdGenerator.nextPkId());
        // 获取当前日期时间并格式化为 "yyyy-MM-dd HH:mm:ss" 的字符串
        String createTimeStr = DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss");
        // 将字符串转换为 Date 类型
        Date createTime = DateUtils.dateTime(YYYY_MM_DD_HH_MM_SS, createTimeStr);
        // 设置 GoodsOrder 的 CreateTime 属性
        goodsOrder.setCreateTime(createTime);
        return goodsOrderMapper.insertGoodsOrder(goodsOrder);
    }

    /**
     * 修改货物订单
     * 
     * @param goodsOrder 货物订单
     * @return 结果
     */
    @Override
    public int updateGoodsOrder(GoodsOrder goodsOrder)
    {
        return goodsOrderMapper.updateGoodsOrder(goodsOrder);
    }

    /**
     * 批量删除货物订单
     * 
     * @param ids 需要删除的货物订单主键
     * @return 结果
     */
    @Override
    public int deleteGoodsOrderByIds(Long[] ids)
    {
        return goodsOrderMapper.deleteGoodsOrderByIds(ids);
    }

    /**
     * 删除货物订单信息
     * 
     * @param id 货物订单主键
     * @return 结果
     */
    @Override
    public int deleteGoodsOrderById(Long id)
    {
        return goodsOrderMapper.deleteGoodsOrderById(id);
    }
}
